package com.ui.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.ciko.code.utils.Util;
import com.mywork.R;


/**
 * Created by x_luthy on 2016/4/22.
 */
public class ResDialog
        extends
        Dialog {
    private Button btnCancel, btnSure;
    private EditText editText;
    private ResDialogListener listener;
    private Context context;

    public ResDialog(Context context, ResDialogListener listener) {
        super(context, R.style.common_dialog);
        setCanceledOnTouchOutside(true);
        this.context = context;
        this.listener = listener;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_res);
        initView();
        btnCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ResDialog.this.dismiss();
            }
        });

        btnSure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (getEidtText().length() > 30) {
                    Util.showToast(context, "字数不超过30字");
                    return;
                }
                listener.clickOk();
                ResDialog.this.dismiss();
            }
        });

    }

    private void initView() {
        btnCancel = (Button) findViewById(R.id.btn_cancel);
        btnSure = (Button) findViewById(R.id.btn_sure);
        editText = (EditText) findViewById(R.id.res_et);
    }

    public String getEidtText() {
        String str = "";
        str = editText.getText().toString();
        return str;
    }
}
